# Copyright © 2021 YongYang
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

agxv_entrypoints = custom_target(
  'agxv_entrypoints',
  input : [vk_entrypoints_gen, vk_api_xml],
  output : ['agxv_entrypoints.h', 'agxv_entrypoints.c'],
  command : [
    prog_python, '@INPUT0@', '--xml', '@INPUT1@', '--proto', '--weak',
    '--out-h', '@OUTPUT0@', '--out-c', '@OUTPUT1@', '--prefix', 'agxv',
  ],
  depend_files : vk_entrypoints_gen_depend_files,
)

libagxv_files = files(
    'agxv_private.h',
    'agxv_device.c',
    'agxv_image.c',
    'agxv_descriptor_set.c',
    'agxv_cmd_buffer.c',
    'agxv_pipeline.c',
    'agxv_pass.c',
    'agxv_queue.c',
    '../../gallium/drivers/asahi/magic.c'
    )

inc_gallium_asahi = include_directories('../../gallium/drivers/asahi')
ld_args_agxv = '-Wl,-undefined,dynamic_lookup'

libvulkan_agxv = shared_library(
  'vulkan_agxv',
  [libagxv_files, agxv_entrypoints],
  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_compiler, inc_util, inc_asahi, inc_gallium_asahi],
  link_args : [ld_args_agxv],
  link_with : [libvulkan_wsi, libasahi_lib, libasahi_decode, libasahi_compiler],
  dependencies: [idep_nir, idep_vulkan_runtime, idep_vulkan_util, idep_vulkan_wsi],
  install : true,
)

agxv_icd = custom_target(
  'agxv_icd',
  input : [vk_icd_gen, vk_api_xml],
  output : 'agxv_icd.@0@.json'.format(host_machine.cpu()),
  command : [
    prog_python, '@INPUT0@',
    '--api-version', '1.0', '--xml', '@INPUT1@',
    '--lib-path', join_paths(get_option('prefix'), get_option('libdir'),
    		  	     'libvulkan_agxv.so'),
    '--out', '@OUTPUT@',
  ],
  build_by_default : true,
  install_dir : with_vulkan_icd_dir,
  install : true,
)